package com.suxin.file;

import java.io.File;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Classname FileMain
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2020/12/17 14:56
 * @Created by ASUS
 */
public class FileMain {

    private static String path = "C:\\Users\\ASUS\\Desktop\\test.txt";

    public static void main(String[] args) throws Exception {

        File file = new File(path);

        FileInputStream fileInputStream = new FileInputStream(file);

        FileChannel channel = fileInputStream.getChannel();

        ByteBuffer allocate = ByteBuffer.allocate(1024);
        allocate.clear();

        int read = 0;

        while ((read = channel.read(allocate)) > 0) {
            channel.read(allocate);
            System.out.println(new String(allocate.array()));
            allocate.clear();
        }

        channel.close();
        fileInputStream.close();

    }

}